<?php

class ObjectModel extends PathModel
{

    private $deep;

    function __construct($deep, $path, $c)
    {
        parent::__construct($path, $c);
        $this->deep = $deep;
    }

    function __get($name)
    {
        //从deep中返回
        if (key_exists($name, $this->deep)) return $this->deep[$name];
        else throw new MissingFieldException(
            $name, $this->path, $this->c->getName());
    }

    function verify($value)
    {
        //首先确定其是对象
        if (!is_array($value) || key_exists(0, $value)) {
            throw new IllegalModelException(
                'Expect Object', $this->path, $this->c->getName());
        }

        foreach ($value as $fieldName => $fieldValue) {
            if (!key_exists($fieldName, $this->deep)) {
                throw new IllegalModelException(
                    'Not Exist', $this->path, $this->c->getName());
            }
            $this->deep[$fieldName]->verify($fieldValue);
        }

        return null;
    }

}
